package offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class offerII_0080 {
    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> result=new LinkedList<>();
        List<Integer> path=new ArrayList<>();
        search(result,path,0,k,n,1);
        return result;
    }
    public void search(List<List<Integer>> result,List<Integer> path,int num,int k,int n,int index){
        if(num==k){
            result.add(new ArrayList<>(path));
            return;
        }
        if(index>n){
            return;
        }
        path.add(index);
        search(result,path,num+1,k,n,index+1);
        path.remove(path.size()-1);
        search(result, path, num, k, n, index+1);

    }
}
